//C:7.10:strgback.cpp -- a function that returns a pointer to char
#include <iostream>

char * buildstr(char c, int n);    // prototype

int main(void)
{
    using namespace std;
    int times;
    char ch;

    cout << "Enter a character: ";
    cin >> ch;
    cout << "enter an integer: ";
    cin >> times;
    char *ps = buildstr(ch, times);
    cout << ps << '\n';
    delete [] ps;    // free memory
    ps = buildstr('+', 20);    // reuse pointer
    cout << ps << " DONE-" << ps << '\n';                               
    delete [] ps;    // free memory
    return 0;                     
}

// builds string amde of n c characters
char * buildstr(char c, int n)
{
    char * pstr = new char[n + 1];
    pstr[n] = '\0'; // terminate string
    while(n-- > 0)
    {  
        pstr[n] = c;    // fill rest of string
    }
    return pstr;
}
